/**
 * Created by Administrator on 2016/10/28.
 */
(function () {
    'use strict';

    angular.module('BlurAdmin.pages.user')
        .controller('UserPageCtrl', UserPageCtrl);

    /** @ngInject */
    function UserPageCtrl($scope, $filter,promiseObj, editableOptions, editableThemes) {
        $scope.smartTablePageSize = 10;



        $scope.smartTableData =promiseObj.data;

        $scope.showStatus = function(user) {
            var selected = [];
            if(user.status) {
                selected = $filter('filter')($scope.statuses, {value: user.status});
            }
            return selected.length ? selected[0].text : 'Not set';
        };


        $scope.removeUser = function(index) {
            $scope.users.splice(index, 1);
        };

        $scope.addUser = function() {
            $scope.inserted = {
                id: $scope.users.length+1,
                name: '',
                status: null,
                group: null
            };
            $scope.users.push($scope.inserted);
        };

        editableOptions.theme = 'bs3';
        editableThemes['bs3'].submitTpl = '<button type="submit" class="btn btn-primary btn-with-icon"><i class="ion-checkmark-round"></i></button>';
        editableThemes['bs3'].cancelTpl = '<button type="button" ng-click="$form.$cancel()" class="btn btn-default btn-with-icon"><i class="ion-close-round"></i></button>';


    }

})();
